/**
 * 用户列表js
 */
var vo={};
$(function(){
	var openWindow=window.document;
	$("#operatorList").height($(openWindow).height()-$(openWindow).height()*0.05-85);
	setInterval(function(){
		$("#operatorList").width(window.parent.$("#centerIframe").width()-124)
	},1000)
	var date=new Date();
	$("#searchText").val("");
	
	 $("#operatorList").datagrid({
			url:$Path+'/admin/operator/getList',
			method:'GET',
			pagination:true,
			pageList: [10,20,50,200],
			loadMsg:'加载中......',
			fitColumns:true,
			sortName:"modifytime",
			sortOrder:"desc",
			rowStyler:function(index,row){   
		        if (row.status==2){   
		        	return 'background-color:'+window.flagColor;
		        }   
		    }, 
			columns:[[
			         {field:'ck',checkbox:true},
					 {field:'operatorid',title:'登录名', align:'center',width:100},
			         {field:'operatorname',title:'姓名', align:'center',width:100},
			         {field:'status',title:'状态', align:'center',width:100,formatter:function(value,row,index){
				        	if(value == 1){
				        		return "启用";
				        	}
				        	else{
				        		return "停用";
				        	}
				         }},
			         {field:'roleName',title:'角色', align:'center',width:100},
			         {field:'secretName',title:'保密级别', align:'center',width:100},
			         {field:'phone',title:'电话', align:'center',width:100},
			         {field:'email',title:'邮箱', align:'center',width:100},
			         {field:'createtime',sortable:true,title:'创建时间', align:'center',width:100,formatter:function(value,row,index){
			        	if(value!=''&&value!=undefined){
			        		return Common.formatterDate2(value);
			        	}
			        	else{
			        		return "";
			        	}
			         }},
			         {field:'id' ,align:'center',title:'操作',width:100,formatter: function(value, row, index){
						 var re=new RegExp("{param}","g");
						 var ref=opt.replace(re,row.operatorid);
						 return ref;
					}}
			     ]]
		});
		//如果操作项为空隐藏操作列
		if(opt==''){
			$("#operatorList").datagrid('hideColumn','id');
		}
		//绑定顶部操作按钮
		$("#operatorList").datagrid({
			toolbar: '#tb'
		});
		//绑定回车事件
		$(document).keydown(function(event){ 
			if(event.keyCode==13){
				window.event.returnValue=false;
			}
		});
})
/**
 * 添加
 */
function add(){
	window.parent.openDialog("添加用户信息",'/admin/operator/addOperator','',550,550,'');
}
/**
 * 编辑
 */
function edit(operid){
	window.parent.openDialog("编辑用户信息",'/admin/operator/editOperator','',550,480,'operid='+operid);
}
/**
 * 查询
 */
function searchCase(){
	vo.searchText=$("#searchText").val();
	$("#operatorList").datagrid('load',vo);
}
/**
 * 批量停用
 * @param idcard
 */
function betchFlag(){
	var rows=$("#operatorList").datagrid('getSelections');
	if(rows.length<=0){
		parent.$.messager.alert('错误','选中的记录为空','error');
		return;
	}
	var auth=window.parent.getAuth();
	parent.$.messager.confirm('停用','您确定要停用选中的操作员吗？',function(data){
		if(data){
			var ids='';
			for(var i=0;i<rows.length;i++){
				ids+=rows[i].operatorid+',';
			}
			var authenticityToken=$("input[name='authenticityToken']").val();
			$.ajax({
				type:'post',
				url: $Path+'/admin/operator/betchDisable',
				data:{ids:ids,authenticityToken:authenticityToken},
				success:function(data){
					if(data.code==200){
						$("#operatorList").datagrid('load',null);
					}
					else{
						parent.$.messager.alert("失败","停用失败："+data.msg,'error');
					}
				},
				error:function(data){
					parent.$.messager.alert("失败","停用失败：",'error');
				}
			});
		}
	})
}
/**
 * 批量启用
 * @param idcard
 */
function betchUnFlag(){
	var rows=$("#operatorList").datagrid('getSelections');
	if(rows.length<=0){
		parent.$.messager.alert('错误','选中的记录为空','error');
		return;
	}
	var auth=window.parent.getAuth();
	parent.$.messager.confirm('停用','您确定要启用选中的操作员吗？',function(data){
		if(data){
			var ids='';
			for(var i=0;i<rows.length;i++){
				ids+=rows[i].operatorid+',';
			}
			var authenticityToken=$("input[name='authenticityToken']").val();
			$.ajax({
				type:'post',
				url: $Path+'/admin/operator/betchEnable',
				data:{ids:ids,authenticityToken:authenticityToken},
				success:function(data){
					if(data.code==200){
						$("#operatorList").datagrid('load',null);
					}
					else{
						parent.$.messager.alert("失败","启用失败："+data.msg,'error');
					}
				},
				error:function(data){
					parent.$.messager.alert("失败","停用失败：",'error');
				}
			});
		}
	})
}

function resetPass(id){
	window.parent.openDialog("重置密码",'/admin/operator/resetPass','',410,300,'operid='+id);
}